home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Utilities / TGZ / tgz.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-23  |  3.4 KB  |  111 lines

  1. #pragma -         /* Maxon-Cpp 1.0 Einstellung fuer C-Mode :-) */
  2.  
  3. /* $VER: TGZ 1.2 (23/09/1997) - Tar Archiver and GZip Script in one command  */
  4. /* (C) 1997 by Finn Jacobs. Feel free to copy. Don't try to manipulate this  */
  5. /* becoz' if you program something in this source-code it would cause bugs   */
  6. /* forever ! :-)                                                             */
  7.  
  8. #include <clib/dos_protos.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <own_string.h>
  12. #include <string.h>
  13.  
  14. void main(int argc, char *argv[])
  15. {
  16.     int x = 1;
  17.  
  18.     int i, j=1, done=1;
  19.     long ret;
  20.     char string[256], dummy[256];
  21.     char zeichen;
  22.     FILE *filehandle;
  23.  
  24.     printf("\nTGZ 1.2 (23/09-1997) written by Finn Jacobs <fjacobs@computerlabor.math.uni-kiel.de>\n");
  25.     if (argc < 3 )
  26.     {
  27.         printf("Usage: \033[1mTGZ <archivefile> <directory> [<file1>,<file2>,...]\033[0m\n\n");
  28.         printf("       Examples:\n");
  29.         printf("               \033[1mtgz test ram:\033[0m\n");
  30.         printf("               (creates an archive 'test.tgz' with contents of RAM:)\n\n");
  31.         printf("               \033[1mtgz test C:List C:Copy Devs:System-Configuratio\033[0m\n");
  32.         printf("               (creates an archive 'test.tgz' with the files C:List, C:Copy\n");
  33.         printf("                and Devs:System-Configuration)\n\n");
  34.         printf(" If exists an archive with the name test.tgz and you don't want to delete it\n");
  35.         printf(" by pressing <n>o then an archive name 'test.tar.gz' will be created.\n\n");
  36.         if ((argc > 1) && (argc < 3)) printf("\nnot enough arguments!\n");
  37.         exit(5);
  38.     }
  39.  
  40.     printf("Adding files ... ");
  41.     strcpy(dummy,"TAR -cf ");
  42.  
  43.     strcpy(string,"");
  44.     sprintf(string, "%s.TAR ", argv[1]);
  45.     stringcat(dummy, string);
  46.     j++;
  47.     
  48.     for (i = j; i < argc; i++)
  49.     {
  50.         strcpy(string,"");
  51.         sprintf(string, "%s ", argv[i]);
  52.         stringcat(dummy, string);
  53.     }
  54.  
  55.     if (x == 0) printf("%s\n", dummy); else Execute(dummy, 0,0);
  56.  
  57.     printf("Done!\nCrunching archivefile ... ");
  58.     strcpy(dummy, "gzip ");
  59.     strcpy(string,"");
  60.     sprintf(string, "%s.TAR", argv[1]);
  61.     stringcat(dummy, string);
  62.  
  63.     if (x == 0) printf("%s\n", dummy); else Execute(dummy, 0,0);
  64.  
  65.     printf("Done!\n");
  66.  
  67.     strcpy(string, "");
  68.     sprintf(string, "%s.TGZ", argv[1]);
  69.     filehandle = fopen(string, "rb");
  70.     if (!(filehandle == 0))
  71.     {
  72.         strcpy(dummy, "");
  73.         sprintf(dummy, "An archiv %s is already existing. Overwrite it (y/n) ?", string);
  74.         printf("%s ", dummy);
  75.  
  76.         while (done == 1)
  77.         {
  78.             zeichen = (char) getchar();
  79.             switch (zeichen) {
  80.              case 'y' :    {
  81.                         fclose(filehandle);
  82.                         strcpy(string, "");
  83.                         sprintf(string, "delete %s.TGZ", argv[1]);
  84.                         if (x == 0) printf("%s\n", string); else Execute(string, 0,0);
  85.                         strcpy(string, "");
  86.                         sprintf(string, "rename %s.TAR.gz %s.TGZ", argv[1], argv[1]);
  87.                         if (x == 0) printf("%s\n", string); else Execute(string, 0,0);
  88.                         printf("%s.TGZ was created !\n", argv[1]);
  89.                         exit(5);
  90.                     }
  91.              case 'n' :    {
  92.                         fclose(filehandle);
  93.                         printf("%s.TAR.GZ was created !\n", argv[1]);
  94.                         exit(5);
  95.                     }
  96.             }
  97.         }
  98.     }
  99.     strcpy(string, "");
  100.     sprintf(string, "rename %s.TAR.gz %s.TGZ", argv[1], argv[1]);
  101.     if (x == 0) printf("%s\n", string); else Execute(string, 0,0);
  102.     printf("%s.TGZ was created !\n", argv[1]);
  103. }
  104.  
  105.  
  106. /* TAR   -       TAR Archiver (Unix)                                       */
  107. /* GZIP  -       GZIP Compression Tool 1.2.4 (Unix)                        */
  108. /* UnTGZ -       UnTGZ Extract-Tool 1.5 (Unix-Like) - by Oliver Wagner     */
  109. /*       -       All Software is free to use and in the archive included.  */
  110.  
  111.